package com.jigu.admin.excetion;

import com.jigu.core.exception.NotFoundException;
import com.jigu.core.utils.ResponseMessage;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 *
 * 统一错误码异常处理
 * Created by toretto on 2017/6/14.
 */
@RestControllerAdvice
public class GlobalErrorInfoHandler {

    @org.springframework.web.bind.annotation.ExceptionHandler(value = GlobalErrorInfoException.class)
    public ResultBody errorHandlerOverJson(HttpServletRequest request,
                                                GlobalErrorInfoException exception) {
        ErrorInfoInterface errorInfo = exception.getErrorInfo();
        ResultBody result = new ResultBody(errorInfo);
        return result;
    }

    @org.springframework.web.bind.annotation.ExceptionHandler(value = NotFoundException.class)
    public ResponseMessage NnotFoundErrorHandlerOverJson(HttpServletRequest request,
                                                         NotFoundException exception) {
        String errorInfo = exception.getMessage();
        return ResponseMessage.error(errorInfo,400);
    }
}
